package com.antler.smt.admin.controller;

import com.antler.smt.admin.annotation.OperateCut;
import com.antler.smt.entity.PurchaserChargeEntity;
import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.request.base.BasePageReq;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.admin.MemberChargeService;
import com.antler.smt.service.admin.PurchaserService;
import com.antler.smt.utils.LogUtil;
import com.antler.smt.validate.DataValidator;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *  会员充值记录接口
 *
 * @author zhangyi
 * @date 2018/4/8 13:37
 */
@RestController
@RequestMapping("/memberCharge")
@Api(description = "会员审核接口")
public class MemberChargeController extends BaseController{

    /**
     * 日志
     */
    private static Logger log = LogUtil.get();

    @Resource
    private MemberChargeService memberChargeService;

    @Resource
    private PurchaserService purchaserService;

    /**
     *  充值审核
     *
     * @param id 充值表id
     * @param auditResult 审核结果 0未审核 1审核通过 2审核不通过
     * @param actualAmmount 实际输入的金额
     * @return
     */
    @PostMapping("/memberRechargeAudit/{id}/{auditResult}")
    @ApiOperation(value = "充值审核", httpMethod = "POST")
    @OperateCut(content = "充值记录审核")
    public Result<ResultCodeEnum> memberRechargeAudit(@PathVariable Long id,
                                                      @PathVariable Integer auditResult,
                                                      @RequestParam(value = "actualAmmount") Long actualAmmount){
        DataValidator.isBlank(String.valueOf(id),"审核充值会员id不能为空");
        DataValidator.isBlank(String.valueOf(auditResult),"审核结果不能为空");
        Result result = null;
            result = memberChargeService.updateMemberCharge(id,auditResult,getUserId(),actualAmmount);
        return result;
    }

    /**
     *  获取待审核充值列表
     *
     * @return
     */
    @GetMapping("/memberChargeList")
    @ApiOperation(value = "获取待审核充值列表", httpMethod = "GET")
    public Result<PageInfo<PurchaserChargeEntity>> memberChargeList(BasePageReq basePageReq){
        Result result = null;
            result = purchaserService.getPurchaserWaitAuditList(basePageReq);
        return result;
    }
}







